<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/22
 * Time: 14:35
 * used to create logs and insert data
 */

namespace App\Http\Controllers;

use Illuminate\Support\Facades\DB;
use Laravel\Lumen\Routing\Controller as BaseController;

class TableController extends BaseController
{
    /**
     * create logs tables
     */
    public function create_table(){
        for($i=0;$i<10;$i++){
            $sql = "CREATE TABLE IF NOT EXISTS `log_".$i."` (
  `id` int(11) NOT NULL,
  `active` varchar(255) NOT NULL,
  `pudate` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
)ENGINE=archive DEFAULT CHARSET=utf8";
            DB::statement($sql);
        }
    }

    public function delete_table(){
        for($i=0;$i<10;$i++){

        }
    }

    public function insert_data(){
        $acts = [
            '正在插入：',
            '正在删除：',
            '正在修改：',
            '正在查询：',
        ];
        for($i=0;$i<100000;$i++){
            $table = "log_".$i%10;
            $active = $acts[mt_rand(0,3)].$i;
            $pubdate = date("Y-m-d H:i:s");
            $sql = "insert into ".$table."(active,pudate) values ('{$active}','{$pubdate}')";
            DB::statement($sql);
        }
        echo "over";
    }
}